#include <stdio.h>


void insertSort(int* a, int num)
{
	int i = 0;
	int j = 0;
	int temp = 0;
	for(i = 1; i < num; ++i)
	{
		temp = a[i];
		for(j = i - 1; j >= 0; --j)
		{
			if(temp < a[j])
			{
				a[j + 1] = a[j];
			}
			else
			{
				break;
			}
		}
		a[j + 1] = temp;
	}
}

void banbuSort(int* a, int num)
{
	int i = 0;
	int j = 0;
	int temp = 0;
	for(i = 0; i < num - 1; ++i)
	{
		for(j = i + 1; j < num; ++j)
		{
			if(a[i] > a[j])
			{
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}
}

void betterBubbleSort(int *a , int num)
{
	int left = 0;
	int right = num -1;
	int temp = 0;
	int i = 0;
	while(left < right)
	{
		for(i = left; i < right; ++i)
		{
			if(a[i] > a[i + 1])
			{
				temp = a[i];
				a[i] = a[i + 1];
				a[i + 1] = temp;
			}
		}
		for(i = right; i > left; --i)
		{
			if(a[i - 1] > a[i])
			{
				temp = a[i];
				a[i] = a[i - 1];
				a[i - 1] = temp;
			}
		}

	}
}

int main(int argc, char **argv)
{
	int array[10] = {9,4,5,6,8,3,2,7,10,1};
	int i = 0;
	banbuSort(array, 10);
	for(; i < 10; ++i)
	{
		printf("%d\n", array[i]);
	}
	return 0;
}
